package bid.yanhj.yanhaijiang.fragmentpageradapter;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * ViewPager 左右滑动控件
 * fragment 类似Activity界面
 * ViewPager + fragment 可左右滑动多页面
 *
 *  view 事件是难以控制的
 *  fragment 布局一般一样 内容不一样
 *
 *  FragmentViewPager 会预加载fragment 和 ViewPager相识
 *
 */
public class MainActivity extends AppCompatActivity {

    private ViewPager mainVp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mainVp = this.<ViewPager>findViewById(R.id.main_vp);

//        List<Fragment> fragments = new ArrayList<>();
//        fragments.add(new TextFragment());
//        fragments.add(new ImgFragment());
//        fragments.add(new TextFragment());

//        MainADapter mainADapter = new MainADapter(getSupportFragmentManager(), fragments);

        MainADapter mainADapter = new MainADapter(getSupportFragmentManager());
        // 建立联系
        mainVp.setAdapter(mainADapter);

    }
}
